package com.itdong.advice;

import com.itdong.vc.ResultVc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
SpringMVC配置全局的异常处理器，统一返回前端信息
 */
@Component
@ControllerAdvice
@ResponseBody
@Slf4j
public class RestContrllerAdvice {

    @ExceptionHandler
    public ResultVc doException(Exception ex){
        log.info("服务器出现异常~~");
        log.info(ex.getMessage());
        ex.printStackTrace();
        return new ResultVc(false, ex.getMessage());
    }


}
